package msu.ml.clusterers;

import weka.core.*;
import weka.clusterers.*;

public class WaveCluster extends Clusterer
{
   private int clusterCount;

   public void buildClusterer(Instances instances) throws Exception
   {
      //Quantize feature space

      //Apply DWT to quantized feature space

      //Find connected components in sub-bands

      //Assign labels to cells

      //Make lookup table

      //Map objects to clusters
   }

   public int clusterInstance(Instance instance) throws Exception
   {
      return -1;
   }

   public int numberOfClusters() throws Exception
   {
      return clusterCount;
   }

   private double [] dwt(double [] input)
   {

      //This function assumes input.length=2^n, n>1
      double[] output = new double[input.length];

      for (int length = input.length >> 1; ; length >>= 1) {
         //length=2^n, WITH DECREASING n
         for (int i = 0; i < length; i++) {
            double sum = input[i*2]+input[i*2+1];
            double difference = input[i*2]-input[i*2+1];
            output[i] = sum;
            output[length+i] = difference;
         }
         if (length == 1) 
            return output;

         //Swap arrays to do next iteration
         System.arraycopy(output, 0, input, 0, length<<1);
      }
   }
}

